package mysql

import "gorm.io/gorm"

//购物车表

type Cart struct {
	gorm.Model
	UserId     int64  `gorm:"type:int(11);not null;index;comment:用户id"`
	GoodsId    int64  `gorm:"type:int(11);not null;index;comment:商品id"`
	GoodsTitle string `gorm:"type:varchar(100);not null;index;;comment:商品标题"`
	GoodsPrice int64  `gorm:"type:int(11);not null;default:0;comment:商品单价"`
	Num        int64  `gorm:"type:int(11);not null;default:0;comment:数量"`
	Checked    int8   `gorm:"type:tinyint(1);not null;default:1;comment:1选中 2 未选中"`
}

// 添加购物车

func (c *Cart) Add() error {
	return Db.Create(&c).Error
}

//购物车列表

func (c *Cart) CartList() (cartList []*Cart, err error) {
	err = Db.Where("user_id = ?", c.UserId).Find(&c).Error
	return
}
